package main

import (
	"flag"
	"gitee.com/man0sions/go-cron/common"
	"gitee.com/man0sions/go-cron/master/service"
	"log"
	"os"
	"os/signal"
	"syscall"
)

var (
	err  error
	conf = flag.String("conf", "./config.json", "conf file")
)

func init() {
	log.SetFlags(log.Lshortfile)
}
func main() {
	flag.Parse()
	if err = common.InitConfig(*conf); err != nil {
		log.Panicln(err)
	}

	if err = common.InitEtcd(); err != nil {
		log.Panicln(err)
	}

	if err = common.InitMongo(); err != nil {
		log.Panicln(err)
	}

	if err = service.InitApi(service.GetRoutes()); err != nil {
		log.Panicln(err)
	}
	if err = common.InitLog();err!=nil{
		log.Panicln(err)
	}


	exitChan := make(chan os.Signal)
	signal.Notify(exitChan, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGSTOP, syscall.SIGTERM)

	for {
		select {
		case <-exitChan:
			log.Println("bye")
			return
		}
	}
}
